<template>
  <div v-if="show" class="modal-overlay" @click.self="handleClose">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title">👋 欢迎使用 AI Tool</h2>
        <button class="modal-close" @click="handleClose">&times;</button>
      </div>
      <div class="modal-body">
        <div class="welcome-message">
          <div class="tip-item">
            <span class="tip-number">1</span>
            <p>大模型的良好运行依赖于你的<strong>明确需求</strong>，描述尽可能的<strong>详细、准确、专业</strong>，则可以帮助大模型更好的完成动作。</p>
          </div>
          <div class="tip-item">
            <span class="tip-number">2</span>
            <p>业务数据通过<strong>"辅助信息"</strong>进行维护，可以帮助大模型更好的理解业务。</p>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <label class="checkbox-container">
          <input type="checkbox" v-model="dontShowAgain">
          <span class="checkmark"></span>
          下次不再显示
        </label>
        <button class="confirm-btn" @click="handleClose">我知道了</button>
      </div>
    </div>
  </div>
</template>

<script>
// 弹窗内容版本控制 - 当内容更新时，需要修改这个版本号
const MODAL_VERSION = '1.0.1';
const MODAL_STORAGE_KEY = 'welcomeModalSettings';

// 静态方法：检查是否需要显示弹窗
export const shouldShowWelcomeModal = () => {
  try {
    const settings = localStorage.getItem(MODAL_STORAGE_KEY);
    if (!settings) return true;
    
    const { version, hideModal } = JSON.parse(settings);
    // 如果版本不同，则需要显示弹窗
    if (version !== MODAL_VERSION) return true;
    // 如果用户选择了不再显示，则不显示
    return !hideModal;
  } catch {
    return true;
  }
};
</script>

<script setup>
import { ref, defineProps, defineEmits } from 'vue';

const props = defineProps({
  show: {
    type: Boolean,
    default: false
  }
});

const emit = defineEmits(['close']);

const dontShowAgain = ref(false);

// 保存弹窗设置
const saveModalSettings = () => {
  const settings = {
    version: MODAL_VERSION,
    hideModal: dontShowAgain.value
  };
  localStorage.setItem(MODAL_STORAGE_KEY, JSON.stringify(settings));
};

// 关闭弹窗
const handleClose = () => {
  saveModalSettings();
  emit('close');
};
</script>

<style scoped>
/* 弹窗样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: linear-gradient(135deg, #ffffff, #f8fafc);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
  width: 90%;
  max-width: 560px;
  max-height: 80vh;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem 1rem;
  background: linear-gradient(135deg, #646cff, #747bff);
  color: white;
  position: relative;
}

.modal-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
}

.modal-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 1.8rem;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.modal-body {
  padding: 2rem;
}

.welcome-message {
  line-height: 1.6;
  color: #334155;
}

.tip-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
  border-radius: 12px;
  border-left: 4px solid #646cff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.tip-item:last-child {
  margin-bottom: 0;
}

.tip-number {
  background: linear-gradient(135deg, #646cff, #747bff);
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  font-size: 0.9rem;
  margin-right: 1rem;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(100, 108, 255, 0.3);
}

.tip-item p {
  margin: 0;
  font-size: 0.95rem;
}

.tip-item strong {
  color: #475569;
  font-weight: 600;
}

.modal-footer {
  padding: 1.5rem 2rem;
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid #e2e8f0;
}

.checkbox-container {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 0.9rem;
  color: #64748b;
  user-select: none;
}

.checkbox-container input[type="checkbox"] {
  opacity: 0;
  position: absolute;
  width: 0;
  height: 0;
}

.checkmark {
  position: relative;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border: 2px solid #cbd5e1;
  border-radius: 4px;
  margin-right: 0.5rem;
  transition: all 0.2s ease;
}

.checkbox-container:hover .checkmark {
  border-color: #646cff;
}

.checkbox-container input:checked ~ .checkmark {
  background: linear-gradient(135deg, #646cff, #747bff);
  border-color: #646cff;
}

.checkbox-container input:checked ~ .checkmark::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.confirm-btn {
  background: linear-gradient(135deg, #646cff, #747bff);
  color: white;
  border: none;
  padding: 0.75rem 2rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(100, 108, 255, 0.2);
}

.confirm-btn:hover {
  background: linear-gradient(135deg, #5b65f0, #6b73ff);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(100, 108, 255, 0.3);
}

.confirm-btn:active {
  transform: translateY(0);
}
</style>